Significantly improve logbook performance when selecting entities#71657
Significantly improve logbook performance when selecting entities#71657balloob merged 17 commits intohome-assistant:devfrom
Conversation
|
Hey there @home-assistant/core, mind taking a look at this pull request as it has been labeled with an integration ( |
|
Thanks @bdraco I'll take a look at the frontend and PR an update to go with this |
|
Not counting JSON encode time (which is only ~10% of the overall picture for single enitites), performance breakdown is now 30% ORM overhead |
|
Its getting to the point where the http overhead is starting to make converting these apis to websocket attractive |
History is actually a better candidate to do first since some of those responses are 100k+ states |
|
Awesome, thanks @bdraco ❤️ |

Breaking change
This change only affects developers using the logbook api.
The
entity_matches_onlyparameter to the logbook api has been been removed as it is no longer necessary. It was originally added for the logbook card to avoid performance problem that this PR has now solved. cc @zsarnettProposed change
This PR introduces a new faster query for selecting context ids for specific entities. The makes the logbook card extremely responsive.
Demo of reloading 3 logbook cards

The previous implementation had to process ALL events inside the time window. The new implementation uses a more efficient database query which is able to narrow the rows returned to only ones that have the context id. In production testing this reduced the api call time from ~800ms to ~50ms on a database that generates 100MiB/day. With larger databases the improvement will be at least two orders of magnitude.
All the logbook queries have been separated into
queries.pyType of change
Additional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: